<?php
	function dbconnect(){
		static $connect = null;
		if($connect == null){
			$connect = mysql_connect("localhost", "root", "");
			mysql_select_db("db_mvc");
		}
		return $connect;
	}
	
	function get_news($news_id){
		$news_req = mysql_query("select * from  news where news_id='$news_id'", dbconnect());				
		
		return mysql_fetch_array($news_req);		
	}
	
	function get_comments($news_id){
		$comment_req = mysql_query("select * from comment where news_id='$news_id'", dbconnect());
		//return mysql_fetch_array($comment_req);		
		
		$list_comment = array();
		while($comment = mysql_fetch_array($comment_req)){
			$list_comment[] = $comment;
		}		
		return $list_comment;		
	}
	
	function insert_comment($comment){
		mysql_query("insert into comment 
			SET news_id='{$comment['news_id']}' , 
				author='" . mysql_real_escape_string($comment['author']). "', 
				content='". mysql_real_escape_string($comment['content']). "', 
				date = NOW()", dbconnect());
		
	}	
?>